package exemple;

public class NativeMath {

    static {
        //绝对路径加载动态库（需要完整库名称）
        System.load("C:/work/develop/idea-space/micro-monitor-server/protocol/target/test-classes/exemple/NativeMath.dll");
        //当库存在于java.library.path中时，可直接加载
        //System.loadLibrary("NativeMath");
    }

    public static native int square(int number);

    public static void main(String[] args) {
        long s = System.nanoTime();
        long hs1 = 0;
        long hs2 = 0;
        for (int i=0 ;i<10000000; i++) {
            jSquare(2);
        }
        System.out.println("源码 耗时: "+(hs1 = System.nanoTime() - s));
        s = System.nanoTime();
        for (int i=0 ;i<10000000; i++) {
            emptyCall();
        }
        System.out.println("源码空调用耗时: "+(hs2 = System.nanoTime() - s));
        s = System.nanoTime();
        for (int i=0 ;i<10000000; i++) {
            square(2);
        }
        System.out.println("java 执行耗时: "+(hs1 - hs2));

        System.out.println("jni 耗时: "+(hs1 = System.nanoTime() - s));
        s = System.nanoTime();
        for (int i=0 ;i<10000000; i++) {
            EveryTypeMap.emptyCall();
        }
        System.out.println("jni空调用耗时: "+(hs2 = System.nanoTime() - s));
        System.out.println("c++ 执行耗时: "+(hs1 - hs2));
        System.out.println(EveryTypeMap.aByte((byte) 0x0b));
        System.out.println(EveryTypeMap.string("abcd"));
        System.out.println(EveryTypeMap.stringSize("abcd"));
    }

    public static void emptyCall(){}

    public static int jSquare(int number) {
        return number * number;
    }
}
